#!/bin/bash

export LANG=zh_CN.UTF-8



echo "guess a number game start! "





echo "name: LIUCHANGXING, id: 24055060146"



NUM1=$(( RANDOM % 100 + 1 ))



START=1

MAX=7



while [ $START -le $MAX ]; do

  

  read -p "$START/$MAX: Please input a num(1-100): " NUM2

  

  if ! [[ "$NUM2" =~ ^[0-9]+$ ]]; then

    echo "Error: Please enter a valid number."

    START=$(( START - 1 ))

  else

    if [ $NUM2 -gt $NUM1 ]; then

      echo "The number you entered is too large."

    elif [ $NUM2 -lt $NUM1 ]; then

      echo "The number you entered is too small."

    else

      echo "You guessed it right!"

      exit 0 

    fi

  fi

  

  START=$(( START + 1 ))

done



echo "You lost!"

echo "The correct number is: $NUM1"



exit 1
